<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>motrackers.centroid_kf_tracker &mdash; Multi-object trackers in Python 1.0.0 documentation</title>
      <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
      <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  <!--[if lt IE 9]>
    <script src="../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
        <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/jquery.js"></script>
        <script src="../../_static/underscore.js"></script>
        <script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script>
        <script src="../../_static/doctools.js"></script>
        <script src="../../_static/sphinx_highlight.js"></script>
    <script src="../../_static/js/theme.js"></script>
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" /> 
</head>

<body class="wy-body-for-nav"> 
  <div class="wy-grid-for-nav">
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
            <a href="../../index.html" class="icon icon-home"> Multi-object trackers in Python
          </a>
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>
        </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
              <ul>
<li class="toctree-l1"><a class="reference internal" href="../../includeme/readmefile.html">Multi-object trackers in Python</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../includeme/readmefile.html#example-tf-mobilenetssd-centroidtracker">Example: <cite>TF-MobileNetSSD + CentroidTracker</cite></a></li>
<li class="toctree-l1"><a class="reference internal" href="../../includeme/readmefile.html#example-yolov3-centroidtracker">Example: <cite>YOLOv3 + CentroidTracker</cite></a></li>
<li class="toctree-l1"><a class="reference internal" href="../../includeme/apidocuments.html">Tracker</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../includeme/apidocuments.html#sort">SORT</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../includeme/apidocuments.html#iou-tracker">IOU Tracker</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../includeme/apidocuments.html#kalman-filter-based-centroid-tracker">Kalman Filter based Centroid Tracker</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../includeme/apidocuments.html#tracks">Tracks</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../includeme/apidocuments.html#kalman-filters">Kalman Filters</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../includeme/apidocuments.html#object-detection">Object Detection</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../includeme/apidocuments.html#utilities">Utilities</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../includeme/apidocuments.html#references-and-credits">References and Credits</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../includeme/apidocuments.html#contributor-covenant-code-of-conduct">Contributor Covenant Code of Conduct</a></li>
</ul>

        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../index.html">Multi-object trackers in Python</a>
      </nav>

      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="../../index.html" class="icon icon-home"></a> &raquo;</li>
          <li><a href="../index.html">Module code</a> &raquo;</li>
      <li>motrackers.centroid_kf_tracker</li>
      <li class="wy-breadcrumbs-aside">
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
             
  <h1>Source code for motrackers.centroid_kf_tracker</h1><div class="highlight"><pre>
<span></span><span class="kn">from</span> <span class="nn">collections</span> <span class="kn">import</span> <span class="n">OrderedDict</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">scipy.spatial</span> <span class="kn">import</span> <span class="n">distance</span>
<span class="kn">from</span> <span class="nn">scipy.optimize</span> <span class="kn">import</span> <span class="n">linear_sum_assignment</span>
<span class="kn">from</span> <span class="nn">motrackers.tracker</span> <span class="kn">import</span> <span class="n">Tracker</span>
<span class="kn">from</span> <span class="nn">motrackers.track</span> <span class="kn">import</span> <span class="n">KFTrackCentroid</span>
<span class="kn">from</span> <span class="nn">motrackers.utils.misc</span> <span class="kn">import</span> <span class="n">get_centroid</span>


<div class="viewcode-block" id="assign_tracks2detection_centroid_distances"><a class="viewcode-back" href="../../includeme/apidocuments.html#motrackers.centroid_kf_tracker.assign_tracks2detection_centroid_distances">[docs]</a><span class="k">def</span> <span class="nf">assign_tracks2detection_centroid_distances</span><span class="p">(</span><span class="n">bbox_tracks</span><span class="p">,</span> <span class="n">bbox_detections</span><span class="p">,</span> <span class="n">distance_threshold</span><span class="o">=</span><span class="mf">10.</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Assigns detected bounding boxes to tracked bounding boxes using IoU as a distance metric.</span>

<span class="sd">    Args:</span>
<span class="sd">        bbox_tracks (numpy.ndarray): Tracked bounding boxes with shape `(n, 4)`</span>
<span class="sd">            and each row as `(xmin, ymin, width, height)`.</span>
<span class="sd">        bbox_detections (numpy.ndarray): detection bounding boxes with shape `(m, 4)` and</span>
<span class="sd">            each row as `(xmin, ymin, width, height)`.</span>
<span class="sd">        distance_threshold (float): Minimum distance between the tracked object</span>
<span class="sd">            and new detection to consider for assignment.</span>

<span class="sd">    Returns:</span>
<span class="sd">        tuple: Tuple containing the following elements:</span>
<span class="sd">            - matches (numpy.ndarray): Array of shape `(n, 2)` where `n` is number of pairs formed after matching tracks to detections. This is an array of tuples with each element as matched pair of indices`(track_index, detection_index)`.</span>
<span class="sd">            - unmatched_detections (numpy.ndarray): Array of shape `(m,)` where `m` is number of unmatched detections.</span>
<span class="sd">            - unmatched_tracks (numpy.ndarray): Array of shape `(k,)` where `k` is the number of unmatched tracks.</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">if</span> <span class="p">(</span><span class="n">bbox_tracks</span><span class="o">.</span><span class="n">size</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span><span class="n">bbox_detections</span><span class="o">.</span><span class="n">size</span> <span class="o">==</span> <span class="mi">0</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">empty</span><span class="p">((</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">),</span> <span class="n">dtype</span><span class="o">=</span><span class="nb">int</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">bbox_detections</span><span class="p">),</span> <span class="n">dtype</span><span class="o">=</span><span class="nb">int</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">empty</span><span class="p">((</span><span class="mi">0</span><span class="p">,),</span> <span class="n">dtype</span><span class="o">=</span><span class="nb">int</span><span class="p">)</span>

    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">bbox_tracks</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
        <span class="n">bbox_tracks</span> <span class="o">=</span> <span class="n">bbox_tracks</span><span class="p">[</span><span class="kc">None</span><span class="p">,</span> <span class="p">:]</span>

    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">bbox_detections</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
        <span class="n">bbox_detections</span> <span class="o">=</span> <span class="n">bbox_detections</span><span class="p">[</span><span class="kc">None</span><span class="p">,</span> <span class="p">:]</span>

    <span class="n">estimated_track_centroids</span> <span class="o">=</span> <span class="n">get_centroid</span><span class="p">(</span><span class="n">bbox_tracks</span><span class="p">)</span>
    <span class="n">detection_centroids</span> <span class="o">=</span> <span class="n">get_centroid</span><span class="p">(</span><span class="n">bbox_detections</span><span class="p">)</span>
    <span class="n">centroid_distances</span> <span class="o">=</span> <span class="n">distance</span><span class="o">.</span><span class="n">cdist</span><span class="p">(</span><span class="n">estimated_track_centroids</span><span class="p">,</span> <span class="n">detection_centroids</span><span class="p">)</span>

    <span class="n">assigned_tracks</span><span class="p">,</span> <span class="n">assigned_detections</span> <span class="o">=</span> <span class="n">linear_sum_assignment</span><span class="p">(</span><span class="n">centroid_distances</span><span class="p">)</span>

    <span class="n">unmatched_detections</span><span class="p">,</span> <span class="n">unmatched_tracks</span> <span class="o">=</span> <span class="p">[],</span> <span class="p">[]</span>

    <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">bbox_detections</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]):</span>
        <span class="k">if</span> <span class="n">d</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">assigned_detections</span><span class="p">:</span>
            <span class="n">unmatched_detections</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>

    <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">bbox_tracks</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]):</span>
        <span class="k">if</span> <span class="n">t</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">assigned_tracks</span><span class="p">:</span>
            <span class="n">unmatched_tracks</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">t</span><span class="p">)</span>

    <span class="c1"># filter out matched with high distance between centroids</span>
    <span class="n">matches</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">t</span><span class="p">,</span> <span class="n">d</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">assigned_tracks</span><span class="p">,</span> <span class="n">assigned_detections</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">centroid_distances</span><span class="p">[</span><span class="n">t</span><span class="p">,</span> <span class="n">d</span><span class="p">]</span> <span class="o">&gt;</span> <span class="n">distance_threshold</span><span class="p">:</span>
            <span class="n">unmatched_detections</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>
            <span class="n">unmatched_tracks</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">t</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">matches</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">t</span><span class="p">,</span> <span class="n">d</span><span class="p">))</span>

    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">matches</span><span class="p">):</span>
        <span class="n">matches</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">matches</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">matches</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">empty</span><span class="p">((</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">),</span> <span class="n">dtype</span><span class="o">=</span><span class="nb">int</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">matches</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">unmatched_detections</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">unmatched_tracks</span><span class="p">)</span></div>


<div class="viewcode-block" id="CentroidKF_Tracker"><a class="viewcode-back" href="../../includeme/apidocuments.html#motrackers.centroid_kf_tracker.CentroidKF_Tracker">[docs]</a><span class="k">class</span> <span class="nc">CentroidKF_Tracker</span><span class="p">(</span><span class="n">Tracker</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Kalman filter based tracking of multiple detected objects.</span>

<span class="sd">    Args:</span>
<span class="sd">        max_lost (int): Maximum number of consecutive frames object was not detected.</span>
<span class="sd">        tracker_output_format (str): Output format of the tracker.</span>
<span class="sd">        process_noise_scale (float or numpy.ndarray): Process noise covariance matrix of shape (3, 3) or</span>
<span class="sd">            covariance magnitude as scalar value.</span>
<span class="sd">        measurement_noise_scale (float or numpy.ndarray): Measurement noise covariance matrix of shape (1,)</span>
<span class="sd">            or covariance magnitude as scalar value.</span>
<span class="sd">        time_step (int or float): Time step for Kalman Filter.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span>
            <span class="bp">self</span><span class="p">,</span>
            <span class="n">max_lost</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
            <span class="n">centroid_distance_threshold</span><span class="o">=</span><span class="mf">30.</span><span class="p">,</span>
            <span class="n">tracker_output_format</span><span class="o">=</span><span class="s1">&#39;mot_challenge&#39;</span><span class="p">,</span>
            <span class="n">process_noise_scale</span><span class="o">=</span><span class="mf">1.0</span><span class="p">,</span>
            <span class="n">measurement_noise_scale</span><span class="o">=</span><span class="mf">1.0</span><span class="p">,</span>
            <span class="n">time_step</span><span class="o">=</span><span class="mi">1</span>
    <span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">time_step</span> <span class="o">=</span> <span class="n">time_step</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">process_noise_scale</span> <span class="o">=</span> <span class="n">process_noise_scale</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">measurement_noise_scale</span> <span class="o">=</span> <span class="n">measurement_noise_scale</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">centroid_distance_threshold</span> <span class="o">=</span> <span class="n">centroid_distance_threshold</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">kalman_trackers</span> <span class="o">=</span> <span class="n">OrderedDict</span><span class="p">()</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">max_lost</span><span class="p">,</span> <span class="n">tracker_output_format</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_add_track</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">frame_id</span><span class="p">,</span> <span class="n">bbox</span><span class="p">,</span> <span class="n">detection_confidence</span><span class="p">,</span> <span class="n">class_id</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tracks</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">next_track_id</span><span class="p">]</span> <span class="o">=</span> <span class="n">KFTrackCentroid</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">next_track_id</span><span class="p">,</span> <span class="n">frame_id</span><span class="p">,</span> <span class="n">bbox</span><span class="p">,</span> <span class="n">detection_confidence</span><span class="p">,</span> <span class="n">class_id</span><span class="o">=</span><span class="n">class_id</span><span class="p">,</span>
            <span class="n">data_output_format</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">tracker_output_format</span><span class="p">,</span> <span class="n">process_noise_scale</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">process_noise_scale</span><span class="p">,</span>
            <span class="n">measurement_noise_scale</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">measurement_noise_scale</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span>
        <span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">next_track_id</span> <span class="o">+=</span> <span class="mi">1</span>

<div class="viewcode-block" id="CentroidKF_Tracker.update"><a class="viewcode-back" href="../../includeme/apidocuments.html#motrackers.centroid_kf_tracker.CentroidKF_Tracker.update">[docs]</a>    <span class="k">def</span> <span class="nf">update</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">bboxes</span><span class="p">,</span> <span class="n">detection_scores</span><span class="p">,</span> <span class="n">class_ids</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">frame_count</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="n">bbox_detections</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">bboxes</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;int&#39;</span><span class="p">)</span>

        <span class="n">track_ids</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tracks</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>
        <span class="n">bbox_tracks</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">track_id</span> <span class="ow">in</span> <span class="n">track_ids</span><span class="p">:</span>
            <span class="n">bbox_tracks</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tracks</span><span class="p">[</span><span class="n">track_id</span><span class="p">]</span><span class="o">.</span><span class="n">predict</span><span class="p">())</span>
        <span class="n">bbox_tracks</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">bbox_tracks</span><span class="p">)</span>

        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">bboxes</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">bbox_tracks</span><span class="p">)):</span>
                <span class="n">track_id</span> <span class="o">=</span> <span class="n">track_ids</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
                <span class="n">bbox</span> <span class="o">=</span> <span class="n">bbox_tracks</span><span class="p">[</span><span class="n">i</span><span class="p">,</span> <span class="p">:]</span>
                <span class="n">confidence</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tracks</span><span class="p">[</span><span class="n">track_id</span><span class="p">]</span><span class="o">.</span><span class="n">detection_confidence</span>
                <span class="n">cid</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tracks</span><span class="p">[</span><span class="n">track_id</span><span class="p">]</span><span class="o">.</span><span class="n">class_id</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_update_track</span><span class="p">(</span><span class="n">track_id</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">frame_count</span><span class="p">,</span> <span class="n">bbox</span><span class="p">,</span> <span class="n">detection_confidence</span><span class="o">=</span><span class="n">confidence</span><span class="p">,</span> <span class="n">class_id</span><span class="o">=</span><span class="n">cid</span><span class="p">,</span> <span class="n">lost</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">tracks</span><span class="p">[</span><span class="n">track_id</span><span class="p">]</span><span class="o">.</span><span class="n">lost</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lost</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_remove_track</span><span class="p">(</span><span class="n">track_id</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">matches</span><span class="p">,</span> <span class="n">unmatched_detections</span><span class="p">,</span> <span class="n">unmatched_tracks</span> <span class="o">=</span> <span class="n">assign_tracks2detection_centroid_distances</span><span class="p">(</span>
                <span class="n">bbox_tracks</span><span class="p">,</span> <span class="n">bbox_detections</span><span class="p">,</span> <span class="n">distance_threshold</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">centroid_distance_threshold</span>
            <span class="p">)</span>

            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">matches</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]):</span>
                <span class="n">t</span><span class="p">,</span> <span class="n">d</span> <span class="o">=</span> <span class="n">matches</span><span class="p">[</span><span class="n">i</span><span class="p">,</span> <span class="p">:]</span>
                <span class="n">track_id</span> <span class="o">=</span> <span class="n">track_ids</span><span class="p">[</span><span class="n">t</span><span class="p">]</span>
                <span class="n">bbox</span> <span class="o">=</span> <span class="n">bboxes</span><span class="p">[</span><span class="n">d</span><span class="p">,</span> <span class="p">:]</span>
                <span class="n">cid</span> <span class="o">=</span> <span class="n">class_ids</span><span class="p">[</span><span class="n">d</span><span class="p">]</span>
                <span class="n">confidence</span> <span class="o">=</span> <span class="n">detection_scores</span><span class="p">[</span><span class="n">d</span><span class="p">]</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_update_track</span><span class="p">(</span><span class="n">track_id</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">frame_count</span><span class="p">,</span> <span class="n">bbox</span><span class="p">,</span> <span class="n">confidence</span><span class="p">,</span> <span class="n">cid</span><span class="p">,</span> <span class="n">lost</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>

            <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">unmatched_detections</span><span class="p">:</span>
                <span class="n">bbox</span> <span class="o">=</span> <span class="n">bboxes</span><span class="p">[</span><span class="n">d</span><span class="p">,</span> <span class="p">:]</span>
                <span class="n">cid</span> <span class="o">=</span> <span class="n">class_ids</span><span class="p">[</span><span class="n">d</span><span class="p">]</span>
                <span class="n">confidence</span> <span class="o">=</span> <span class="n">detection_scores</span><span class="p">[</span><span class="n">d</span><span class="p">]</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_add_track</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">frame_count</span><span class="p">,</span> <span class="n">bbox</span><span class="p">,</span> <span class="n">confidence</span><span class="p">,</span> <span class="n">cid</span><span class="p">)</span>

            <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">unmatched_tracks</span><span class="p">:</span>
                <span class="n">track_id</span> <span class="o">=</span> <span class="n">track_ids</span><span class="p">[</span><span class="n">t</span><span class="p">]</span>
                <span class="n">bbox</span> <span class="o">=</span> <span class="n">bbox_tracks</span><span class="p">[</span><span class="n">t</span><span class="p">,</span> <span class="p">:]</span>
                <span class="n">confidence</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tracks</span><span class="p">[</span><span class="n">track_id</span><span class="p">]</span><span class="o">.</span><span class="n">detection_confidence</span>
                <span class="n">cid</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tracks</span><span class="p">[</span><span class="n">track_id</span><span class="p">]</span><span class="o">.</span><span class="n">class_id</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_update_track</span><span class="p">(</span><span class="n">track_id</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">frame_count</span><span class="p">,</span> <span class="n">bbox</span><span class="p">,</span> <span class="n">confidence</span><span class="p">,</span> <span class="n">cid</span><span class="p">,</span> <span class="n">lost</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>

                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">tracks</span><span class="p">[</span><span class="n">track_id</span><span class="p">]</span><span class="o">.</span><span class="n">lost</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">max_lost</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_remove_track</span><span class="p">(</span><span class="n">track_id</span><span class="p">)</span>

        <span class="n">outputs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_tracks</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tracks</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">outputs</span></div></div>
</pre></div>

           </div>
          </div>
          <footer>

  <hr/>

  <div role="contentinfo">
    <p>&#169; Copyright 2021, Aditya M. Deshpande.</p>
  </div>

  Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    provided by <a href="https://readthedocs.org">Read the Docs</a>.
   

</footer>
        </div>
      </div>
    </section>
  </div>
  <script>
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>